﻿CREATE PROCEDURE [dbo].[RoleMembership_InsertUpdate]

	@roleId				BIGINT,

	@userAccountId		BIGINT,

	@modifiedId			VARCHAR (0060)

AS

	BEGIN 

		MERGE RoleMembership

			USING (SELECT @roleId, @userAccountId) AS Source (RoleId, UserAccountId)

				ON ((RoleMembership.RoleId = Source.RoleId) AND (RoleMembership.UserAccountId = Source.UserAccountId))

			WHEN MATCHED THEN 

				UPDATE SET 

					ModifiedId = @modifiedId,

					ModifiedDateTime = GETDATE ()

			WHEN NOT MATCHED THEN 

				INSERT (RoleId, UserAccountId, CreateId, CreateDateTime, ModifiedId, ModifiedDateTime) 

					VALUES (@roleId, @userAccountId, @modifiedId, GETDATE (), @modifiedId, GETDATE())

		; -- MERGE ( END )


	END

	